package org.flynenu.ums.logic.impl;

import org.flynenu.ums.common.entity.base.User;
import org.flynenu.ums.common.ticket.Ticket;
import org.flynenu.ums.dao.UserDao;
import org.flynenu.ums.logic.IGownsman;
import org.flynenu.ums.logic.IJury;
import org.flynenu.ums.logic.IPolice;
import org.flynenu.ums.logic.IPrinter;


public class GownsmanImpl implements IGownsman {
	private IPrinter printer = null; //BeansManager.instance().generateBean(BeansEnum.Printer);//LogicFactory.getPrinter();
	private IPolice polic = null; //BeansManager.generateBean(BeansEnum.Police); //LogicFactory.getPolic();
	private IJury jury = null; //BeansManager.generateBean(BeansEnum.Jury); //LogicFactory.getJury();
	
	private UserDao userDao = null; //DaoFactory.getUserCell();
	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void setPolic(IPolice polic) {
		this.polic = polic;
	}
	
	public void setJury(IJury jury) {
		this.jury = jury;
	}

	public void setPrinter(IPrinter printer) {
		this.printer = printer;
	}
	
	@Override
	public Ticket applyTicket(int uid) {
		Ticket ticket = null;
		if(polic.surveyUser(uid)){
			ticket = printer.generateTickeNo(uid);
			
			// 警察备案
			polic.backupTciket(ticket);
		}
		
		return ticket;
	}

	@Override
	public boolean authenticatTicket(int uid, String ticketNo) {
		return polic.surveyLogined(uid, ticketNo);
	}

	@Override
	public void regist(User user) {
		jury.check(user);
		
		userDao.regist(user);
	}
}
